package com.cgw.room.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.cgw.room.R;
import com.cgw.room.bean.StatusItemBean;

import java.util.List;

public class StatusItemAdapter  extends ArrayAdapter<StatusItemBean> {
    private List<StatusItemBean> items;
    private final int resource;
    private Context context;
    public StatusItemAdapter(@NonNull Context context, int resource, List<StatusItemBean> items) {
        super(context, resource);
        this.context = context;
        this.resource = resource;
        this.items = items;
        Log.i("[List]", "Create : items = " + items.size());
    }
    @NonNull
    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        Log.i("[List]", "position = " + position);
        StatusItemBean item = (StatusItemBean) getItem(position);
        assert item != null;

        @SuppressLint("ViewHolder")
        View view = LayoutInflater.from(context).inflate(resource, null);
        Log.i("[List]", "view = " + view);
        TextView tvName = view.findViewById(R.id.status_item_name);
        TextView tvValue = view.findViewById(R.id.status_item_value);
        tvName.setText(item.getName());
        tvValue.setText(item.getValue());

        Log.i("[List]", "N = " + item.getName() + " V = " + item.getValue());

        return view;
    }

    @Override
    public int getCount() {
        Log.i("[List]", "getCount = " + items.size());
        return items.size(); // 确保返回正确数量
    }
    @Override
    public StatusItemBean getItem(int position) {
        return items.get(position);
    }
}
